/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CastleDefense;

/**
 *
 * @author Administrator
 */
import CastleDefense.units.Unit;
import java.util.ArrayList;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

//This statement means that class "UnitList.java" is the root-element of our example
@XmlRootElement(namespace = "UnitList")
public class UnitList
{
    // XmLElementWrapper generates a wrapper element around XML representation
    @XmlElementWrapper(name = "UnitList")
    // XmlElement sets the name of the entities
    @XmlElement(name = "unit")
    private ArrayList<Unit> UnitList;
    private ArrayList<Unit> tmpList = new ArrayList<Unit>();

    public void setUnitList(ArrayList<Unit> UnitList)
    {
        this.UnitList = UnitList;
    }

    public ArrayList<Unit> getUnitsList()
    {
        return UnitList;
    }

    public void appendUnitList(ArrayList<Unit> UnitList)
    {
        for(int i=0; i<UnitList.size(); i++)
        {
            tmpList.add(UnitList.get(i));
        }
        this.UnitList = tmpList;
    }

    public Unit getUnitByName(String name)
    {
        for (Unit myUnit : UnitList)
        {
            if(myUnit.getName().equals(name))
                return myUnit;
        }
        return null;
    }

    public String getAllData()
    {
        String txt = "";
        for (Unit myUnit : UnitList)
        {
            txt += myUnit.getAllData();
            return txt;
        }
        return "";
    }

    public Integer size()
    {
        return UnitList.size();
    }
}
